# Maintainer: David Runge <dvzrv@archlinux.org>
# Maintainer: Bruno Pagani <archange@archlinux.org>
# Contributor: Eric Bélanger <eric@archlinux.org>

pkgname=quodlibet
pkgver=4.6.0
pkgrel=1
pkgdesc="Music player and music library manager"
arch=(any)
url="https://quodlibet.readthedocs.io/"
license=(GPL-2.0-or-later)
depends=(
  dbus-python
  gdk-pixbuf2
  gobject-introspection-runtime
  gstreamer
  gst-plugins-base
  gst-plugins-base-libs
  gtk3
  hicolor-icon-theme
  libsoup3
  pango
  python
  python-cairo
  python-feedparser
  python-gobject
  python-mutagen
  python-requests
)
makedepends=(
  python-build
  python-installer
  python-setuptools
  python-sphinx_rtd_theme
  python-wheel
)
# python-raven python-senf are currently vendored
checkdepends=(
  gst-plugins-bad
  gst-plugins-good
  gst-plugins-ugly
  # python-polib  # TODO: package python-polib
  python-pytest
  python-pyvirtualdisplay
  xorg-server-xvfb
)
optdepends=(
  'gst-libav: Extra media codecs for the GStreamer backend'
  'gst-plugins-bad: Extra media codecs for the GStreamer backend; Audio Pitch / Speed, Crossfeed, Submit Acoustic Fingerprints plugins'
  'gst-plugins-good: Extra media codecs, PulseAudio support for the GStreamer backend; Audio Compressor, Karaoke, Replay Gain plugins'
  'gst-plugins-ugly: Extra media codecs for the GStreamer backend'
  'gtksourceview3: Undo and redo support in multiline text fields'
  'kakasi: Kana/Kanji Simple Inverter plugin'
  'libappindicator-gtk3: Appindicator support in the Tray Icon plugin'
  'libkeybinder3: Multimedia key support under non Gnome setups'
  'libmodplug: MOD support'
  'python-musicbrainzngs: MusicBrainz Lookup, MusicBrainz Sync plugins'
  'python-paho-mqtt: MQTT Publisher plugin'
  'python-pyinotify: Automatic Library Update plugin'
  'rygel: UPnP AV Media Server plugin'
  'webkit2gtk: Web Lyrics plugin'
  'xine-lib: Alternative audio backend'
)
source=(https://github.com/$pkgname/$pkgname/releases/download/release-$pkgver/$pkgname-$pkgver.tar.gz{,.sig})
sha512sums=('d17ed0ba14aa86eaf103fdc5feaeda74575e4bd9d9e55dae07679afb50e279c82b66b7429b0435c36663a9865141c168d3ff56a25c64f9694818f722362db7e9'
            'SKIP')
b2sums=('aab5a6a651081caf4a2e6935ccaab505ee1102e6433b28bcb704de2ef9d17190db30314f7efba07b3d3a15919eb8171bc81de68d60de8166efeddaaa7813d00c'
        'SKIP')
validpgpkeys=(0EBF782C5D53F7E5FB02A66746BD761F7A49B0EC) # Christoph Reiter <reiter.christoph@gmail.com>

prepare() {
  cd $pkgname-$pkgver
  # Fix zsh completions dir
  sed -e 's|vendor-completions|site-functions|' -i gdist/zsh_completions.py
}

build() {
  cd $pkgname-$pkgver
  python -m build --wheel --no-isolation
}

check() {
  local pytest_options=(
    -vv
    -k 'not TFlake8'  # do not run linter checks
    --ignore tests/quality  # we are not interested in code quality tests
    --deselect tests/test_po.py::TPOTFILESIN::test_missing  # we do not care about missing tests for translations
    --deselect tests/plugin/test_prefs.py::TestPluginPrefs::test_plugin_pref[SqueezeboxSyncPlugin]  # certainly do not want to do a telnet connection during test
    --deselect tests/plugin/test_prefs.py::TestPluginPrefs::test_plugin_pref[SqueezeboxPlaylistPlugin]  # certainly do not want to do a telnet connection during test
    --deselect tests/test_operon.py::TOperonEdit::test_remove_all  # https://github.com/quodlibet/quodlibet/issues/3966
    --deselect tests/test_util_cover.py::TCoverManager::test_invalid_glob  # https://github.com/quodlibet/quodlibet/issues/4021
  )
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $pkgname-$pkgver
  python -m installer --destdir=test_dir dist/*.whl
  export PYTHONPATH="$PWD/test_dir/$site_packages:$PYTHONPATH"
  pytest "${pytest_options[@]}"
}

package() {
  cd $pkgname-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 {README,NEWS}.rst -t "$pkgdir/usr/share/doc/$pkgname/"
}
